$(document).ready(function () {
    layui.use(['laypage','jquery', 'layer', 'table', 'form', 'util'], function(){
        let form = layui.form;
        let id = GetUrlParam("id");
        let createTime = GetUrlParam("createTime");
        if (id === null || id === undefined || id === "") {
            return;
        }
        if (createTime === null || createTime === undefined || createTime === "") {
            alert("系统错误 createTime为空")
            return;
        }
        let url = serverPre + "/manager/scs/v2/signLog/preview/"+id+"?createTime="+toDateString(createTime);
        let result = requestGet(url);
        if(result === undefined || result === null){
            errorMsg("返回数据为空");
            return;
        }
        if(result.templateName !== ""){
            $('#templateName').val(result.templateName);
        }
        if(result.templateResource !== ""){
            $('#templateResource').val(result.templateResource);
        }
        if(result.signType !== ""){
            $('#signType').val(result.signType);
        }
        if(result.jsonBody !== ""){
            $('#requestData').val(result.jsonBody);
        }
        if(result.officialKeyWords !== null){
            let keywords = result.officialKeyWords;
            $.each(keywords,function (i,item) {
                let content = "<input type='checkbox' name='officalSealBox' lay-skin='primary' disabled='disabled' checked title='"+item+"'>";
                $("#officialKeyWords").append(content);
            });
            form.render();
        }
    });

    //取消
    $("#closeWin").click(function () {
        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
        parent.layer.close(index);
    });

    $("#preViewBtn").click(function () {
        let signatureStatus = GetUrlParam("signatureStatus");
        if (signatureStatus == 2) {
            let contractUri = GetUrlParam("contractUri");
            let channelNo = GetUrlParam("channelNo");
            if(contractUri === null || contractUri === ""){
                alert("该合同不存在！");
                return false
            }
            let url = serverPre + "/manager/scs/v2/requestLog/contract/"+contractUri +"?channelNo="+channelNo;;
            let result = requestGet(url);
            if(result === undefined || result.contractUri === undefined || result.contractUri === ""){
                alert("发生异常，请联系管理员！")
            }else {
                window.open(result.contractUri,'_blank');
                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                parent.layer.close(index);
            }
        } else {
            alert("该签章处理失败无法查看证书");
            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
            parent.layer.close(index);
        }
    })
});
